import type { IRentCustomerDTO, IRentMachineOrderInfoList } from "@/types/rentMachineManage/rentMachineOrderInfo";

/* 移交订单 */
function useDispatchOrder(fn?: () => void) {
  const customerVisible = ref(false);
  const customerForm = ref<IRentCustomerDTO>({
    id: 0,
    customer_id: ""
  });

  /* 打开移交订单dialog */
  function handleOrderDispatch(row: IRentMachineOrderInfoList) {
    customerForm.value.id = row.id;
    if (row.customer) {
      customerForm.value.customer_id = row.customer.id;
    }
    customerVisible.value = true;
  }

  /* 移交订单成功回调 */
  function handleDispatchOrderSuccess() {
    customerVisible.value = false;
    if (fn) {
      fn();
    }
  }

  return {
    customerVisible,
    customerForm,
    handleOrderDispatch,
    handleDispatchOrderSuccess
  };
}

export default useDispatchOrder;
